package com.wuuxiang.polestar.core.zookeeper.surpass;

import org.apache.curator.RetryPolicy;
import org.apache.curator.retry.ExponentialBackoffRetry;

import com.google.common.base.Preconditions;
import com.wuuxiang.polestar.core.ConfigProfile;

/**********************************************************
 * 项目名称：polestar
 * 类描述： 新版基类
 * 创建人：夏鸿鹏
 * 创建时间：2017-11-24 18:33
 * 修改备注：
 *
 **********************************************************/

public class ZookeeperSurPassConfigProfile extends ConfigProfile {

    // 重试策略
    private static final ExponentialBackoffRetry DEFAULT_RETRY_POLICY = new ExponentialBackoffRetry(1000, 3);

    // zookeeper地址
    private final String connectStr;

    // 项目组名称
    private final String teamName;

    // 是否加载默认分组设置
    private final boolean isLoadDef;

    // 重试策略
    private final RetryPolicy retryPolicy;

    // 是否开启本地缓存, 基础为当前用户目录下的.polestar
    private final boolean openLocalCache;

    public ZookeeperSurPassConfigProfile(final String connectStr, final String teamName, final boolean isLoadDef) {
        this(connectStr, teamName, isLoadDef, false);
    }

    public ZookeeperSurPassConfigProfile(final String connectStr, final String teamName, final boolean isLoadDef,
                                         final boolean openLocalCache) {
        this(connectStr, teamName, isLoadDef, openLocalCache, DEFAULT_RETRY_POLICY);
    }

    public ZookeeperSurPassConfigProfile(final String connectStr, final String teamName, final boolean isLoadDef,
                                         final boolean openLocalCache, final RetryPolicy retryPolicy) {
        super(teamName);
        this.connectStr = Preconditions.checkNotNull(connectStr);
        this.teamName = Preconditions.checkNotNull(teamName);
        this.isLoadDef = Preconditions.checkNotNull(isLoadDef);
        this.retryPolicy = Preconditions.checkNotNull(retryPolicy);
        this.openLocalCache = openLocalCache;
    }

    public String getConnectStr() {
        return connectStr;
    }

    public RetryPolicy getRetryPolicy() {
        return retryPolicy;
    }

    public String getTeamName() {
        return teamName;
    }

    public boolean isOpenLocalCache() {
        return openLocalCache;
    }

    public boolean isLoadDef() {
        return isLoadDef;
    }

    @Override
    public String toString() {
        return "ZookeeperSurPassConfigProfile{" + "connectStr='" + connectStr + '\''
                + ", teamName='" + teamName + '\''
                + ", isLoadDef='" + isLoadDef + '\'' + ", retryPolicy="
                + retryPolicy + ", openLocalCache=" + openLocalCache + '}';
    }

}
